package cn.zzmx.controller;


import cn.zzmx.entity.Order;
import cn.zzmx.entity.ResultMsg;
import cn.zzmx.service.IOrderService;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("order")
public class OrderController {

    @Autowired
    private IOrderService iOrderService;



    @GetMapping("/queryOrderAll")
    public ResultMsg<Order> queryOrderAll(Integer page, Integer limit){
        PageInfo<Order> orderPageInfo = iOrderService.queryOrderAll(page, limit);

        ResultMsg<Order> msg = new ResultMsg<>();
        msg.setCode(0);
        msg.setCount(orderPageInfo.getTotal());
        msg.setData(orderPageInfo.getList());
        msg.setMsg("查询成功");

        return msg;
    }


    @RequestMapping("/queryOrderPassengerById")
    public ResultMsg<Order> queryOrderPassengerById(@Param("id") String id){

        ResultMsg<Order> msg = new ResultMsg<>();
        msg.setCode(0);
        msg.setData(iOrderService.queryOrderPassengerById(id));
        msg.setMsg("查询成功");

        return msg;
    }


    @RequestMapping("/deleteOrderById")
    public ResultMsg<Order> deleteOrderById(@Param("id") String id){

        iOrderService.deleteOrderById(id);
        ResultMsg<Order> msg = new ResultMsg<>();
        msg.setCode(0);
        msg.setMsg("删除成功");

        return msg;
    }


}
